package com.zxbg.dao;

import com.zxbg.domain.InfoBlock;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface InfoBlockDao {
    @Select("select * from info_block where info_module_id = #{info_module_id} and tenant_id = #{tenant_id}")
    public List<InfoBlock> getListByModuleId(@Param("info_module_id") String info_module_id, @Param("tenant_id") Integer tenant_id);

    @Update("update info_block set `status` = 2, click_num = 0 where id = #{id}")
    public boolean setBlockRun(Integer id);

    @Update("update info_block set `status` = 1 where id = #{id}")
    public boolean setBlockStop(Integer id);

    @Insert("insert into info_block values(null, #{info_module_id}, #{title}, #{from}, #{tenant_id}, #{public_range}, #{creator_id}, #{status}, #{click_num}, #{rotation_url}, #{create_time}, #{type_id}, null, #{annex_url}, #{start_time}, #{content}, #{end_time}, #{is_top}, #{top_day}, #{data_type})")
    public int addInfoBlock(InfoBlock infoBlock);

    @Update("update info_block set `status` = 1 where id = #{id}")
    public int stopInfoBlock(Integer id);

    @Select("select * from info_block where id = #{id}")
    public InfoBlock getInfoBlockById(Integer id);

    @Update("update info_block set is_top = #{is_top} where id = #{id}")
    public int changeIsTop(@Param("id") Integer id, @Param("is_top") Integer is_top);

    @Delete("delete from info_block where id = #{id}")
    public int deleteInfoBlock(Integer id);

    @Update("update info_block set `status` = #{status} where id = #{id}")
    public int publishInfoBlock(@Param("id") Integer id, @Param("status") Integer status);

    @Update("update info_block set `status` = 2 where id = #{id}")
    public boolean setBlockReRun(Integer id);

    @Update("update info_block set start_time = NOW() where id = #{id}")
    public int setBlockStartTimeNow(Integer id);

    @Select("select * from info_block where type_id = #{type_id}")
    public List<InfoBlock> getListByTypeId(Integer type_id);

    @Update("update info_block set type_id = #{type_id} where id = #{id}")
    public int updateBlockTypeId(@Param("id") Integer id, @Param("type_id") Integer type_id);

    @Update("update info_block set info_module_id = #{info_module_id}, title = #{title}, `from` = #{from}, public_range = #{public_range}, rotation_url = #{rotation_url}, type_id = #{type_id}, annex_url = #{annex_url}, start_time = #{start_time}, content = #{content}, end_time = #{end_time}, is_top = #{is_top}, top_day = #{top_day}, data_type = #{data_type} where id = #{id}")
    public int updateInfoBlock(InfoBlock infoBlock);

    @Select("select * from info_block where rotation_url is not null and status = 2 and tenant_id = #{tenant_id}")
    public List<InfoBlock> getActiveLunBoPic(Integer tenant_id);

    @Update("update info_block set viewed_employee_id = #{viewed_employee_id}, click_num = #{click_num} where id = #{id}")
    public int updateViewed(InfoBlock infoBlock);

    @Select("select * from info_block where info_module_id = 'allNews' and rotation_url is null and status = 2 and tenant_id = #{tenant_id}")
    public List<InfoBlock> getActiveNews(Integer tenant_id);

    @Select("select * from info_block where info_module_id = 'NoticesManage' and status = 2 and tenant_id = #{tenant_id}")
    public List<InfoBlock> getActiveNotices(Integer tenant_id);

    @Select("select * from info_block where info_module_id = 'RulesManage' and status = 2 and tenant_id = #{tenant_id}")
    public List<InfoBlock> getActiveRegulation(Integer tenant_id);
}
